// Tags: DP
#include <algorithm>
#include <cstdio>
using par = std::pair<int, int>;

const int N = 1e5 + 5;
int cnt, top, n, stk[N];
par a[N];

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("P6564 [POI2007] 堆积木KLO.in", "r", stdin);
  freopen("P6564 [POI2007] 堆积木KLO.out", "w", stdout);
#endif
#endif

  scanf("%d", &n);
  for (int i = 1, tmp; i <= n; ++i) {
    scanf("%d", &tmp);
    if (tmp <= i) {
      a[++cnt].first = tmp;
      a[cnt].second = i;
    }
  }
  if (!cnt) { return puts("0"), 0; }
  std::sort(a + 1, a + cnt + 1, [](const par &lhs, const par &rhs) {
    return (lhs.second - lhs.first == rhs.second - rhs.first)
               ? lhs.second < rhs.second
               : lhs.second - lhs.first < rhs.second - rhs.first;
  });
  stk[++top] = a[1].first;
  for (int i = 2, pos; i <= cnt; ++i) {
    if (a[i].first > stk[top]) stk[++top] = a[i].first;
    else {
      pos = std::lower_bound(stk + 1, stk + top + 1, a[i].first) - stk;
      stk[pos] = a[i].first;
    }
  }
  printf("%d", top);
  return 0;
}